#include "stdafx.h"

const double EnemyBomb::interval = 0.03;

EnemyBomb::EnemyBomb(double x, double y)
	:AbstractBullet(x, y)
{

}

EnemyBomb::~EnemyBomb()
{
}

bool EnemyBomb::update(double dtime)
{
	time += dtime;
	renderTime += dtime;

	if (time > lifeSpan)
	{
		die();
		return false;
	}

	if (renderTime > interval)
	{
		currentPage = (currentPage + 1) % frameCount;
		currentImage = ImageMgr::getInstance()->get(foldername + "/" + std::to_string(currentPage) + ".png");
		renderTime = 0;
	}

	return true;
}

bool EnemyBomb::render()
{
	return currentImage->render(getDisplayX(), getDisplayY(), 0);
}

void EnemyBomb::die()
{
	static const double range = 200;

	if (hero->distance(x, y) <= range)
	{
		hero->loseHP(damage);
	}

	FrameAnimation * anim = new FrameAnimation(x, y);
	anim->setCount(11);
	anim->setFolder("image/animation/blast2");
	anim->setInterval(0.03);
	anim->setMap(map);

	AnimationMgr::getInstance()->add(anim);
}

void EnemyBomb::setImageSet(const std::string & foldername)
{
	this->foldername = foldername;

	currentImage = ImageMgr::getInstance()->get(foldername + "/" + std::to_string(currentPage) + ".png");
}